This invention generally relates to computer systems. More specifically, this invention relates to an object-oriented method and apparatus for automatically selecting among multiple implementations of objects in a computer program.
The development of the EDVAC computer system of 1948 is often cited as the beginning of the computer era. Since that time, computer systems have found their way into just about every aspect of the American lifestyle. One reason for this proliferation is the ability of computer systems to perform a variety of tasks in an efficient manner. The mechanisms used by computer systems to perform these tasks are called computer programs.
Like computer systems themselves, the development of computer programs has evolved over the years. The EDVAC system used what was called a xe2x80x9cone addressxe2x80x9d computer programming language. This language allowed for only the most rudimentary computer programs. By the 1960s, improvements in computer programming languages led to computer programs that were so large and complex that it was difficult to manage and control their development and maintenance.
Therefore, the focus of the 1970s was on developing programming methodologies and environments that could better accommodate the increasing complexity and cost of large computer programs. One such methodology is called Object Oriented Programming (OOP). Though it has been some time since the fundamental notions of OOP were first developed, OOP systems are becoming more and more prevalent because it is felt that use of OOP can greatly increase the efficiency of computer programmers. Not surprisingly, objects are central to OOP technology. A single object represents an individual operation or a group of operations that are performed by a computer system upon information controlled by the object. Objects can be thought of as autonomous agents that work together to perform certain tasks. Sometimes entire computer programs are made up of groupings of objects and sometimes objects are simply accessed by more traditional computer programs to perform one specific task or subtask. For a general background regarding objects and object-oriented programming, see Grady Booch, Object Oriented Design with Applications, (Benjamin/Cummings Publishing Co. 1991).
While the use of OOP has led to greater programmer efficiency, that same use brings with it several challenges that have yet to be overcome by prior art mechanisms. For example, the specific programming (i.e., implementation) of an object will determine the performance of that object. While one implementation of an object may be optimized for a particular portion of the computer program, that same implementation of the object may be inefficient for a different portion of the computer program. Thus, by using only a single way to implement an object, the performance of a computer program that uses the object will not be optimized.
Programmers have recognized the need to provide multiple implementations of objects to provide a choice of different implementations according to different performance requirements and design parameters of the computer program. For example, one implementation of an object may store data in an array. Storing data in an array is a relatively efficient use of memory provided that the approximate number of items to be stored is known. However, to retrieve a particular piece of data from the array, the array must be searched until the desired piece of data is located. As a result, the slower speed of retrieving a particular piece of data from the array is a trade-off for the memory efficiency of the array. In contrast, a different implementation of the same object may use a hash table instead of an array. A hash table uses memory less efficiently, but has the advantage of quick retrieval of any particular piece of data. In one portion of a computer program, speed may be a primary concern, so the implementation that uses the hash table would be preferred. In another portion of the computer program, memory usage may be a primary concern, so the implementation that uses the array would be preferred. However, in the past, the selection between multiple implementations of objects was performed manually, with the programmer specifically selecting a particular implementation for each object in the computer program, or for only certain objects. This process of manually selecting between multiple implementations of objects is very time-consuming and inefficient. Without a mechanism for automatically selecting among multiple implementations of objects without programmer intervention, the efficiency of computer programs will be impaired, resulting in less than optimal performance from computers running these computer programs.
According to the present invention, a mechanism allows a compiler to automatically select among multiple implementations of objects. In accordance with a first embodiment, the compiler uses a weighted cost function for each implementation to determine which implementation is most advantageous for a given object based on an estimate of execution frequency of each function of the object. In accordance with a second embodiment, the compiler uses information relating to the functions issued against a given object to select an implementation with the most efficient interface that contains all the issued functions.
The foregoing and other objects, features and advantages of the invention will be apparent from the following more particular description of preferred embodiments of the invention, as illustrated in the accompanying drawings.